package com.zwk.views;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import com.zwk.views.*;
import com.zwk.util.*;

public class WKMainView extends JFrame{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private static final int DEFAULT_WIDTH = 300;
	private static final int DEFAULT_HEIGHT = 300;
	public static JFrame frame;
	public WKMainView(String title) {
		frame = new JFrame();
		frame.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT);
		frame.setTitle(title);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		Toolkit kit = Toolkit.getDefaultToolkit();
		Dimension screenSize = kit.getScreenSize();
		int screenWidthpx = screenSize.width;
		int screenHeightpx = screenSize.height;
		frame.setLocation(screenWidthpx / 3, screenHeightpx / 3);
		frame.setLocationByPlatform(false);
		
		Image image = new ImageIcon(this.getClass().getResource("/WKImage/top1.jpg")).getImage();
		frame.setIconImage(image);
		
		WKMainPanel loginPanel = new WKMainPanel();
		frame.setContentPane(loginPanel);
		frame.setVisible(true);

		frame.addWindowListener(new WKWindowHandler());
	}
	private class WKMainPanel extends JPanel {
		/**
		 * 
		 */
		private static final long serialVersionUID = 1L;
		JLabel picLabel;
	    JButton tchButton, stdButton;
	    JPanel buttonPanel;
	    
	    public WKMainPanel() {
	    	picLabel = new JLabel();
	    	tchButton = new JButton("点击跳转到教师登录界面");
	    	tchButton.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent e) {
					WKTchLoginView tchView = new WKTchLoginView();
					frame.dispose();
				}
			});
	    	stdButton = new JButton("点击跳转到学生登录界面");
	    	stdButton.addActionListener(new ActionListener() {
	    		@Override
	    		public void actionPerformed(ActionEvent e) {
	    			WKLoginView stdView = new WKLoginView("学生登录窗口");
	    			frame.dispose();
	    		}
	    	});
	    	buttonPanel = new JPanel();
	 
	    	setLayout(new BorderLayout());
	    	
	    	picLabel.setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT/2 + 30);
	    	
	    	ImageIcon image = new ImageIcon(this.getClass().getResource("/WKImage/top1.jpg"));
	    	image.setImage(image.getImage().getScaledInstance(picLabel.getWidth(), picLabel.getHeight(), Image.SCALE_DEFAULT));;
	    	picLabel.setIcon(image);
	    	buttonPanel.add(picLabel);
	    	buttonPanel.add(stdButton);
	    	buttonPanel.add(tchButton);
	    	add(buttonPanel, BorderLayout.CENTER);
	    }
	
	}
	
	public static void main(String[] args) {
		new WKMainView("学生考勤管理系统");
	}
}